import Page
from Page import Service
from Base.Base import Base
from selenium.webdriver.common.by import By


class ServiceIndexPage(Base):
    """
    车服务首页
    """

    def __init__(self, driver):
        Base.__init__(self, driver)

        # 待保养公里数
        self.index_km_number_text = (By.XPATH, Service.RESOURCE_ID.format("tv_kilometre_detail"))

        # 待保养周期
        self.index_month_number_text = (By.XPATH, Service.RESOURCE_ID.format("tv_time_detail"))

        # 去维保按钮
        self.index_maintain_btn = (By.XPATH, Service.RESOURCE_ID.format("btn_maintain"))

        # 右侧列表分类标题, 使用需传入分类的中文名
        self.index_list_category_title_text = (By.XPATH, Page.TEXT.format(""))

        # 右侧列表分类封面, 使用需传入分类的中文名
        self.index_list_category_cover_img = (By.XPATH, Service.index_list_category_cover_img.format(""))

    def get_km_number(self):
        """
        获取待保养里程数

        :return:
        """
        return self.find_element_o(self.index_km_number_text)

    def get_month_number(self):
        """
        获取待保养周期

        :return:
        """
        return self.find_element_o(self.index_month_number_text)

    def get_list_category_cover(self, category_name):
        """
        根据传入的分类名, 获取分类封面

        :param category_name:  分类中文名
        :return:
        """
        self.index_list_category_cover_img = (By.XPATH, Service.index_list_category_cover_img.format(category_name))
        return self.find_element_o(self.index_list_category_cover_img)

    def click_maintain(self):
        """
        点击`去维保`按钮

        :return:
        """
        self.click_element(self.index_maintain_btn)

    def click_list_category(self, category_name):
        """
        根据传入的分类名, 点击分类

        :param category_name: 分类中文名
        :return:
        """
        self.index_list_category_cover_img = (By.XPATH, Service.index_list_category_cover_img.format(category_name))
        self.click_element(self.index_list_category_cover_img)
